<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Room;

class GeneratedRoomUid extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'generatedRoomUid';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '生成房间注册UID';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $roomModel = new Room();
        $roomDataList = $roomModel->getSingle([], ['room_uid']);
        $roomDataIdArray = array_column($roomDataList, 'room_uid','room_uid');

        $generateArray = [];
        for ($i = 10000; $i < 99999; $i++) {
            if (filterUUID($i)) {
                continue;
            }

            if (!array_key_exists($i, $roomDataIdArray)) {
                array_push($generateArray, $i);
            }
        }

        // 数组顺序打乱
        shuffle($generateArray);

        foreach ($generateArray as $value) {
            Redis::RPUSH("ROOM:UID:GENERATED:DB", $value);
        }
    }
}
